#!/bin/bash
# Version 0.0.1
#time=`date "+%Y-%m-%d-%H"`

#num=`tail -1000 /var/log/httpd/access_log.$time | awk '{print $NF}' | grep '^.\{8\}'|wc -l`
num=`tail -1000 /var/log/nginx/access.log|awk -F '"' '($(NF-1)>0.1) {print $(NF-1)}'|wc -l`
# Getting parameters:
while getopts "w:c:h" OPT;do
case $OPT in
"w")warning=$OPTARG;;
"c")critical=$OPTARG;;
"h")help;;
esac
done

#Comparing the result and setting the correct level:
if [[ $num -ge $critical ]]; then
	msg="CRITICAL"
	status=2
else if [[ $num -ge $warning ]]; then
	msg="WARNING"
	status=1
else
	msg="OKOKOK"
	status=0
    fi
fi

#Printing the results:
echo "$msg - More than 0.1s to the last 1000 requests Num $num"

exit $status
